********************************************************************************************
**** DESCRIPTIVE
**** This program compares means and equality of means for control variables
********************************************************************************************

	capt prog drop descriptive

	program descriptive, eclass

	syntax varlist [if] [in], [ * ]
	*marksample touse
	*markout `touse'
	tempname m_mu_b m_mu_1_b m_mu_2_b m_sd_b m_sd_1_b m_sd_2_b m_coef_c_b m_d_se_c_b m_d_p_c_b m_mu_f m_mu_1_f m_mu_2_f m_sd_f m_sd_1_f m_sd_2_f m_coef_c_f m_d_se_c_f m_d_p_c_f obs                       
                           
	foreach var of local varlist {
		
		* Treatment 
				
		qui ttest `var' if round == 2010, by(mother)
		
			mat `m_mu_b' = nullmat(`m_mu_b'), (r(mu_1)*r(N_1)+r(mu_2)*r(N_2))/(r(N_1)+r(N_2))
			mat `m_mu_1_b' = nullmat(`m_mu_1_b'), r(mu_1)
			mat `m_mu_2_b' = nullmat(`m_mu_2_b'), r(mu_2)
			mat `m_sd_b' = nullmat(`m_sd_b'), r(sd)
			mat `m_sd_1_b' = nullmat(`m_sd_1_b'), r(sd_1)
			mat `m_sd_2_b' = nullmat(`m_sd_2_b'), r(sd_2)
			mat `obs' = nullmat(`obs'), r(N_1)+r(N_2)
			mat `obs' = nullmat(`obs'), r(N_1)
			mat `obs' = nullmat(`obs'), r(N_2)
						
		qui reg `var' mother if round == 2010, cluster(id_mun)
		
			matrix b = e(b)
			matrix v = e(V)
			mat `m_coef_c_b' = nullmat(`m_coef_c_b'), b[1,1]
			mat `m_d_se_c_b' = nullmat(`m_d_se_c_b'), sqrt(v[1,1])
			mat `m_d_p_c_b' = nullmat(`m_d_p_c_b'), 2*ttail(e(df_r),abs(b[1,1]/sqrt(v[1,1])))
			mat `obs' = nullmat(`obs'), e(N)
					
		qui ttest `var' if round == 2012, by(mother)
		
			mat `m_mu_f' = nullmat(`m_mu_f'), (r(mu_1)*r(N_1)+r(mu_2)*r(N_2))/(r(N_1)+r(N_2))
			mat `m_mu_1_f' = nullmat(`m_mu_1_f'), r(mu_1)
			mat `m_mu_2_f' = nullmat(`m_mu_2_f'), r(mu_2)
			mat `m_sd_f' = nullmat(`m_sd_f'), r(sd)
			mat `m_sd_1_f' = nullmat(`m_sd_1_f'), r(sd_1)
			mat `m_sd_2_f' = nullmat(`m_sd_2_f'), r(sd_2)
			mat `obs' = nullmat(`obs'), r(N_1)+r(N_2)
			mat `obs' = nullmat(`obs'), r(N_1)
			mat `obs' = nullmat(`obs'), r(N_2)
						
		qui reg `var' mother if round == 2012, cluster(id_mun)
		
			matrix b = e(b)
			matrix v = e(V)
			mat `m_coef_c_f' = nullmat(`m_coef_c_f'), b[1,1]
			mat `m_d_se_c_f' = nullmat(`m_d_se_c_f'), sqrt(v[1,1])
			mat `m_d_p_c_f' = nullmat(`m_d_p_c_f'), 2*ttail(e(df_r),abs(b[1,1]/sqrt(v[1,1])))
			mat `obs' = nullmat(`obs'), e(N)
			
			
	}
		
	foreach mat in m_mu_b m_mu_1_b m_mu_2_b m_sd_b m_sd_1_b m_sd_2_b m_coef_c_b m_d_se_c_b m_d_p_c_b m_mu_f m_mu_1_f m_mu_2_f m_sd_f m_sd_1_f m_sd_2_f m_coef_c_f m_d_se_c_f m_d_p_c_f {
		mat coln ``mat'' = `varlist'
	}

	tempname b V
	mat `b' = `m_coef_c_b'*0
	mat `V' = `b''*`b'
	eret post `b' `V'
	eret local cmd "descriptive"
	
	mat temp = `obs'
	eret scalar N1 = temp[1,1] // Full sample baseline
	eret scalar N2 = temp[1,2] // HH sample baseline
	eret scalar N3 = temp[1,3] // Mother sample baseline
	eret scalar N4 = temp[1,4] // Regression sample baseline
	eret scalar N5 = temp[1,5] // Full sample follow-up
	eret scalar N6 = temp[1,6] // HH sample follow-up
	eret scalar N7 = temp[1,7] // Mother sample follow-up
	eret scalar N8 = temp[1,8] // Regression sample follow-up
		
	foreach mat in m_mu_b m_mu_1_b m_mu_2_b m_sd_b m_sd_1_b m_sd_2_b m_coef_c_b m_d_se_c_b m_d_p_c_b m_mu_f m_mu_1_f m_mu_2_f m_sd_f m_sd_1_f m_sd_2_f m_coef_c_f m_d_se_c_f m_d_p_c_f obs {
		eret mat `mat' = ``mat''
	}
	
	end
